<!-------教师修改学生成绩界面---------->

<!DOCTYPE html>
<html lang="en">
<head xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <meta charset="UTF-8">
    <title>学生信息管理系统</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <script src="/js/jquery-3.6.1.min.js"></script>
    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">

</head>
<body>
<br/>
<div class="container-fluid">

    <br/>
    <form class="form-inline">
        <div class="form-group">
            <label for="searchName">请输入学生的姓名:</label>
            <input type="text" class="form-control" id="searchName" placeholder="姓名" name="searchName">
        </div>
        <button type="button" class="btn btn-default btn-primary" onclick="search();">查询</button>
        <a>&nbsp;&nbsp;&nbsp;&nbsp;</a>
        <button type="button" class="btn btn-default btn-primary" onclick="free();">清空输入框</button>
        <a>&nbsp;&nbsp;&nbsp;&nbsp;</a>
        <button type="button" class="btn btn-default btn-primary" onclick="Back();">返回主页</button>
    </form>

    <a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>

</div>
<br/><br/>
<div>
    <table class="table table-bordered " id="stuTable">

    </table>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="myModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">学生信息表单</h4>
            </div>
            <div class="modal-body">

                <form id="formStudent">

                    <input hidden="hidden" id="id" name="id"/>

                    <div class="form-group">
                        <label for="no">学号</label>  <label style="color: red">(此项只能由管理员进行修改)</label>
                        <input type="text" onfocus="this.blur()" class="form-control" id="no" name="no" placeholder="学号">
                    </div>

                    <div class="form-group">
                        <label for="name">姓名</label> <label style="color: red">(此项只能由管理员进行修改)</label>
                        <input type="text" onfocus="this.blur()" class="form-control" id="name" name="name" placeholder="姓名">
                    </div>

                    <div class="form-group">
                        <label for="sex">性别</label> <label style="color: red">(此项只能由管理员进行修改)</label>
                        <input onfocus="this.blur()" class="form-control" id="sex" name="sex" placeholder="性别">
                        </input>
                    </div>

                    <div class="form-group">
                        <label for="banji">班级</label> <label style="color: red">(此项只能由管理员进行修改)</label>
                        <input type="text" onfocus="this.blur()" class="form-control" id="banji" name="banji" placeholder="班级">
                    </div>

                    <div class="form-group">
                        <label for="cno">班级编号</label> <label style="color: red">(此项只能由管理员进行修改)</label>
                        <input type="text" onfocus="this.blur()" class="form-control" id="cno" name="cno" placeholder="班级">
                    </div>

                    <div class="form-group">
                        <label for="score">成绩</label>
                        <input type="text" class="form-control" id="score" name="score" placeholder="成绩">
                    </div>

                </form>
                <!--表单结束-->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="saveStudent();">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script src="/js/bootstrap.min.js"></script>
<script src="/plugins/bootstraptable/bootstrap-table.min.js"></script>
<script src="/plugins/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>


<script type="text/javascript">

    //查找
    function search(){
        var len=document.getElementById("searchName").value.length;
        if(len==0)
        {
            alert("输入的内容不能为空");
        }

        $('#stuTable').bootstrapTable("destroy");
        loadTable();

    }

    //清空输入框
    function free(){

        document.getElementById("searchName").value='';

    }

    //输入框清空后点击返回
    function Back(){

        $('#stuTable').bootstrapTable("destroy");
        loadTable();
    }

    //新增或者更新
    function saveStudent(){
        var data=$("#formStudent").serialize();
        var id=$("#id").val();
        if(id<1){
            //新增
            $.ajax({

                url:"/webapi/student/insert",
                method:"post",
                data:data

            }).done(function (){

                $('#stuTable').bootstrapTable("destroy");
                loadTable();
                $('#myModal').modal('hide')

            })
        }
        else{
            //更新
            $.ajax({

                url:"/webapi/student/update",
                method:"put",
                data:data

            }).done(function (){

                $('#stuTable').bootstrapTable("destroy");
                loadTable();
                $('#myModal').modal('hide')

            })

        }
    }

    //更新
    function editStudent(id){

        $('#myModal').modal('show');

        $.ajax({
            url:'/webapi/student/get/'+id

        }).done(function(rs){

            $("#id").val(rs.id);
            $("#no").val(rs.no);
            $("#banji").val(rs.banji);
            $("#cno").val(rs.cno);
            $("#name").val(rs.name);
            $("#password").val(rs.password);
            $("#sex").val(rs.sex);
            $("#score").val(rs.score);

        })

    }

    function loadTable(){

        $('#stuTable').bootstrapTable({
            url: '/webapi/student/getbypage',

            striped:true,  //隔行变色效果
            pagination:true,  //底部会显示分页条
            singleSelect: false,  //true会禁止多选
            pageSize:5,   //每页数据条数
            pageNumber:1,   //首页页码
            sidePagination: "server",  //设置在哪分页

            queryParams:function(params) {

                var paraObj={
                    size: params.limit,
                    page: params.offset/params.limit,
                    sort:"id",
                    direct:"desc",
                    name:$("#searchName").val()

                };

                return paraObj;
            },

            columns: [{
                field: 'id',
                title: '序号'
            }, {
                field: 'no',
                title: '学号'
            }, {
                field: 'name',
                title: '姓名'
            }, {
                field: 'sex',
                title: '性别'
            }, {
                field: 'score',
                title: '成绩'
            }, {
                field:'banji',
                title:'班级'
            },{
                field:'cno',
                title:'班级编号'
            },{
                field: 'id',
                title: '&emsp;&emsp;操作',
                formatter: function (value, row, meta) {
                    var operator = "<a href='#' onclick='editStudent("+ value +")'>点击修改成绩</a>"
                    return operator;
                }
            },]
        });

    } //end of loadTable()

    $(function (){

        loadTable();
    })

</script>
</body>
</html>